<template>
  <component
    :is="templateName"
    v-if="templateName"
    :show-header="true"
    :temp="temp"
    @fetch-entity="openEntity"
    @fetch-data="callBack"
  />
</template>
<script>
export default {
  name: 'PortalNewTemplateNewIndex',
  props: {
    layout: {
      type: Object,
      default: () => {
        return {}
      }
    },
    temp: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      mb: null,
      dl: null,
      fl: null,
      templateName: null
    }
  },
  watch: {
    temp: {
      handler(newTemp, oldTemp) {
        if (undefined !== newTemp.data && newTemp.data !== null) {
          this.mb = newTemp.data.mb
          this.dl = newTemp.data.mbdl
          this.fl = newTemp.data.mbfl
          const path = './' + this.dl + '/' + this.fl + '/' + this.mb
          const res = () => import(`${path}`)
          this.templateName = res
        } else {
          this.templateName = null
        }
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  },
  methods: {
    openEntity(data) {
      this.$emit('fetch-entity', data)
    },
    callBack(data) {
      // 点击更多回调
      this.$emit('fetch-data', data)
    }
  }
}
</script>

<style scoped></style>
